import request from '../utils/request';
import { MENU_DATA } from '../constants/constants.js';

export async function login(payload) {
  // return request('/account/login', {
  //   method: 'POST',
  //   headers: { 'Content-Type': 'application/json' },
  //   body: JSON.stringify(payload),
  //   cache: 'no-cache',
  // });
  return { code: 200, data: { username: 'admin', realName: '超级管理员', role: 'SUPERADMIN' } };
}

export async function getMenu(payload) {
  // return request('/account/login', {
  //   method: 'POST',
  //   headers: { 'Content-Type': 'application/json' },
  //   body: JSON.stringify(payload),
  //   cache: 'no-cache',
  // });
  return { code: 200, data: MENU_DATA };
}
export async function getCurrentAccount() {
  return request('/account/getCurrentAccount', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    cache: 'no-cache',
  });
}
export async function logout() {
  // return request('/account/logout', {
  //   method: 'POST',
  //   headers: { 'Content-Type': 'application/json' },
  //   cache: 'no-cache',
  // });
  return { code: 200 };
}

export async function changePassword(payload) {
  return request('/account/changePassword', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload),
    cache: 'no-cache',
  });
}

export async function query(payload) {
  return request(`teaknowledgesearchkey/_query/${payload.page}/${payload.size}`, {
    method: 'GET',
    cache: 'no-cache',
  });
}

export async function add(payload) {
  const formData = {};
  formData.keyword = payload.formData.keyword;
  formData.property_names = payload.formData.propertyNames.join(',');
  return request('teaknowledgesearchkey/', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(formData),
    cache: 'no-cache',
  });
}
export async function update(payload) {
  const formData = {};
  formData.keyword = payload.formData.keyword;
  formData.property_names = payload.formData.propertyNames.join(',');
  return request(`teaknowledgesearchkey/${payload.id}`, {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(formData),
    cache: 'no-cache',
  });
}

export async function del(payload) {
  return request(`teaknowledgesearchkey/${payload.id}`, {
    method: 'DELETE',
    cache: 'no-cache',
  });
}

// export async function batchDel(payload) {
//   return request('teaknowledgesearchkey/_mdelete', {
//     method: 'DELETE',
//     body: JSON.stringify(payload.ids),
//   });
// }
